package com.linkage.jz.bankruptcy.activity.Project.ZQUser;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.linkage.jz.bankruptcy.BankruptcyApp;
import com.linkage.jz.bankruptcy.R;
import com.linkage.jz.bankruptcy.base.BaseActivity;
import com.linkage.jz.bankruptcy.bean.SerializedZQApplyFileList;
import com.linkage.jz.bankruptcy.bean.ZQBaseProjectCrDecInfo;
import com.linkage.jz.bankruptcy.widget.PublicNoticeDialog;
import com.linkage.seapeak.activity.project.ExamineAdvActivity;
import com.linkage.seapeak.view.QuickPopView;

import static com.linkage.jz.bankruptcy.activity.Project.ZQUser.CreateZQFristApplyActivity.KEY_CREDITORID;
import static com.linkage.jz.bankruptcy.activity.Project.ZQUser.CreateZQFristApplyActivity.KEY_CREDITOR_RIGHTS_ID;
import static com.linkage.jz.bankruptcy.activity.Project.ZQUser.CreateZQFristApplyActivity.KEY_EDITING;
import static com.linkage.jz.bankruptcy.activity.Project.ZQUser.CreateZQFristApplyActivity.KEY_EDITING_FILE_LISTS;
import static com.linkage.jz.bankruptcy.activity.Project.ZQUser.CreateZQFristApplyActivity.KEY_TYPE;

public  class CreateZQFristApplyThreeActivity extends BaseActivity implements OnClickListener, ZQApplyView {
    private static final String TAG = CreateZQFristApplyThreeActivity.class.getSimpleName();

    Button top_back;
    TextView top_mune1, top_mune2;
    private EditText etAccountName, etBankBranch, etAccount;

    private static ZQBaseProjectCrDecInfo mEditInfo;
    private int mType;
    private String mCreditorId;
    private String mProjectId;
    private TempSavePresenter mTempSavePresenter;
    private String mCreditorRightsId;
    private SerializedZQApplyFileList mSerializedZQApplyFileLists;

    private TextView popClick;

    public static void start(Context context,
                             String creditorId, String projectId, int type, ZQBaseProjectCrDecInfo editInfo,
                             SerializedZQApplyFileList serializedZQApplyFileLists, String creditorRightsId) {
        Intent intent = new Intent(context, CreateZQFristApplyThreeActivity.class);
        intent.putExtra(KEY_CREDITORID, creditorId);
        intent.putExtra(KEY_PROJECTID, projectId);
        intent.putExtra(KEY_TYPE, type);
        mEditInfo = editInfo;
//        intent.putExtra(KEY_EDITING, editInfo);
        intent.putExtra(KEY_EDITING_FILE_LISTS, serializedZQApplyFileLists);
        intent.putExtra(KEY_CREDITOR_RIGHTS_ID, creditorRightsId);
        context.startActivity(intent);
    }

    @Override
    public void initData() {

    }

    @Override
    public void setListener() {
        top_back.setOnClickListener(this);
        top_mune1.setOnClickListener(this);
        top_mune2.setOnClickListener(this);
    }

    @Override
    public void initTitle() {
        ((TextView) findViewById(R.id.top_title)).setText("银行账户");
    }

    @Override
    public void initView() {
        top_back = findViewById(R.id.top_back);
        top_mune1 = findViewById(R.id.top_mune1);
        top_mune2 = findViewById(R.id.top_mune2);
        etAccountName = findViewById(R.id.et_account_name);
        etBankBranch = findViewById(R.id.et_bank_branch);
        etAccount = findViewById(R.id.et_account);

        popClick = findViewById(R.id.pop_click);
        /**
         * 弹窗
         */
        popClick.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                QuickPopView.show(CreateZQFristApplyThreeActivity.this);
            }
        });

        if (mEditInfo != null) {
            if (mEditInfo.getBankAccount() != null) etAccount.setText(mEditInfo.getBankAccount());
            if (mEditInfo.getBank() != null) etBankBranch.setText(mEditInfo.getBank());
            if (mEditInfo.getBankAccountName() != null) etAccountName.setText(mEditInfo.getBankAccountName());
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_create_zq_frist_three_apply);
        mType = getIntent().getIntExtra(KEY_TYPE, 0);
        mCreditorId = getIntent().getStringExtra(KEY_CREDITORID);
        mProjectId = getIntent().getStringExtra(KEY_PROJECTID);
//        mEditInfo = getIntent().getParcelableExtra(KEY_EDITING);
        mSerializedZQApplyFileLists = getIntent().getParcelableExtra(KEY_EDITING_FILE_LISTS);
        mCreditorRightsId = getIntent().getStringExtra(KEY_CREDITOR_RIGHTS_ID);
        super.onCreate(savedInstanceState);
        mTempSavePresenter = new TempSavePresenter(this,
                mShapeLoadingDialog, mProjectId, mCreditorId, mType, mCreditorRightsId, mEditInfo, mSerializedZQApplyFileLists);
    }

    private  PublicNoticeDialog publicLoginNoticeDialog;
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.top_back:
                onBackPressed();
                break;
            case R.id.top_mune1:
                if (checkInputValid()) {
                    publicLoginNoticeDialog = new PublicNoticeDialog(BankruptcyApp.activityRef, new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {

                            if (view.getId() == R.id.btn_chancel_notice) {//暂存

                            } else if (view.getId() == R.id.ll_close) {

                                return;
                            } else {//生成
                                mTempSavePresenter.submit();
                            }

//                                    RegisterActivity.start(BankruptcyApp.activityRef);
                            publicLoginNoticeDialog.dismiss();


                        }
                    }, 1, "提示", "确定录入申报信息？", "取消", "确定");
                    publicLoginNoticeDialog.show();
                }
                break;
            case R.id.top_mune2:
                mTempSavePresenter.tempSave();
                break;
            default:
                break;
        }
    }

    private boolean checkInputValid() {
        boolean validate = etAccountName.getText().length() > 0;
//        if (!validate) {
//            Toast.makeText(this, "请填写账户名", Toast.LENGTH_SHORT).show();
//            return false;
//        }
//        validate = etBankBranch.getText().length() > 0;
//        if (!validate) {
//            Toast.makeText(this, "请填写开户行", Toast.LENGTH_SHORT).show();
//            return false;
//        }
//        validate = etAccount.getText().length() > 0;
//        if (!validate) {
//            Toast.makeText(this, "请填写账号", Toast.LENGTH_SHORT).show();
//            return false;
//        }
        return true;
    }

    @Override
    public void syncEdit() {
        mEditInfo.setBankAccount(etAccount.getText().toString());
        mEditInfo.setBankAccountName(etAccountName.getText().toString());
        mEditInfo.setBank(etBankBranch.getText().toString());
    }

    @Override
    public String getUserToken() {
        return super.getUserToken();
    }

    @Override
    public Context getContext() {
        return this;
    }

    @Override
    public void onBackPressed() {
        mTempSavePresenter.onBackPressed();
    }

}

